package www.ld.com.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import www.ld.com.entities.Dept;

import java.util.List;

@RestController
public class DeptController {
    //private static final String REST_PATH="http://127.0.0.1:8001";
    private static final String REST_URL_PREFIX = "http://SPRING-CLOUD-DEMO-PROVIDER"; //
    @Autowired
    private RestTemplate getRestTemplate;

    @GetMapping("findAll")
    public List<Dept> findAll() {
        return getRestTemplate.getForObject(REST_URL_PREFIX + "/findAll", List.class);
    }

    @GetMapping("test/{id}")
    public String test(@PathVariable("id") Long id) {
        return getRestTemplate.getForObject(REST_URL_PREFIX + "/test/"+id, String.class);
    }
}
